/*
 * Proja - project management software
 * Copyright (C) 2012  Oleg Kasian
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

package org.proja.core.entity;

import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.proja.core.entity.enumerations.JournalizedType;

/**
 *
 * @author oleg
 */
@Entity
@Table(name = "JOURNALS")
public class Journal extends AbstractEntity {
    
    @Id
    @SequenceGenerator(name = "JournalSeq", sequenceName = "JOURNALS_SEQ")
    @GeneratedValue(generator = "JournalSeq")
    @Column(name = "ID", updatable = false)
    private Long id;

    @Column(name = "TYPE", nullable = false)
    private JournalizedType type;

    @Column(name = "JOURNALIZED_ID", nullable = false)
    private Long journalizedId;

    @Column(name = "ATTRIBUTE", nullable = false)
    private String attribute;

    @Lob
    @Column(name = "OLD_VALUE")
    private String oldValue;

    @Lob
    @Column(name = "NEW_VALUE")
    private String newValue;

    @ManyToOne(cascade = CascadeType.DETACH, optional = true)
    @JoinColumn(name = "SUBMITTER", nullable = true)
    @NotFound(action = NotFoundAction.IGNORE)
    private User submitter;

    @Temporal(TemporalType.TIME)
    @Column(name = "CREATED_ON", updatable = false)
    private Date createdOn = new Date();
    
    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(final Long id) {
        this.id = id;
    }

    public JournalizedType getType() {
        return type;
    }

    public void setType(final JournalizedType type) {
        this.type = type;
    }

    public Long getJournalizedId() {
        return journalizedId;
    }

    public void setJournalizedId(final Long journalizedId) {
        this.journalizedId = journalizedId;
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(final String attribute) {
        this.attribute = attribute;
    }

    public String getOldValue() {
        return oldValue;
    }

    public void setOldValue(final String oldValue) {
        this.oldValue = oldValue;
    }

    public String getNewValue() {
        return newValue;
    }

    public void setNewValue(final String newValue) {
        this.newValue = newValue;
    }

    public User getSubmitter() {
        return submitter;
    }

    public void setSubmitter(final User submitter) {
        this.submitter = submitter;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

}
